package controller

import (
	"mini-app/internal/app/admin/service"
	"strconv"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
)

type Banner struct{}

func (Banner) Detail(c *gin.Context) {
	id := c.Query("id")
	detail := service.Banner{}.Detail(c.Request.Context(), id)
	response.JSON(c, detail, nil)
}
func (Banner) List(c *gin.Context) {
	name := c.Query("name")
	position, _ := strconv.Atoi(c.Query("position"))
	startTime, _ := strconv.Atoi(c.Query("start_time"))
	endTime, _ := strconv.Atoi(c.Query("end_time"))
	page, _ := strconv.Atoi(c.Query("page"))
	limit, _ := strconv.Atoi(c.Query("limit"))
	list, total := service.Banner{}.List(
		c.Request.Context(),
		name,
		position,
		int64(startTime), int64(endTime),
		1,
		page, limit,
	)
	response.JSON(c, gin.H{
		"list":  list,
		"total": total,
	}, nil)
}
